﻿using M_Bom.API.Application.Command.BomCommand;
using M_Bom_Repository.Interface;
using MediatR;

namespace M_Bom.API.Application.CommandHandler.BomCommandHandler
{
    public class BomDeleteCommandHandler : IRequestHandler<BomDeleteCommand, int>
    {
        protected readonly IBom bom;

        public BomDeleteCommandHandler(IBom bom)
        {
            this.bom = bom;
        }

        public async Task<int> Handle(BomDeleteCommand request, CancellationToken cancellationToken)
        {
            var id = request.Bomid;
            foreach (var item in id)
            {
                var res = await bom.GetModelAsync(item);
                res.IsDeleted = true;

                await bom.UpdateAsync(res);
            }
            return 1;
        }
    }
}
